#ifndef GLOBAL_DEFS_HPP
#define GLOBAL_DEFS_HPP

//#define NTC_TEMP_SENSOR
#define I2C_TEMP_SENSOR

#ifdef NTC_TEMP_SENSOR

#define PRIM_DR_PIN			27
#define SEC_DR_PIN			26
#define THIRD_DR_PIN		25

#define LED_PIN	13

// heater by resistor, cooled by wind
#define MODEL_RES_HEATER

#define FAN_SPEED_PIN_0 34
#define FAN_SPEED_PIN_1 39

#endif

#ifdef I2C_TEMP_SENSOR

// Heat/Cool1 on Liu's board
// Center TEC
#define MULTI_PRIM_DR_PIN0 33
#define MULTI_SEC_DR_PIN0 32
// Left TEC
// Heat/Cool2 on Liu's board
#define MULTI_PRIM_DR_PIN1 26
#define MULTI_SEC_DR_PIN1 25
// Right TEC
// Heat/Cool3 on Liu's board
#define MULTI_PRIM_DR_PIN2 14                                 
#define MULTI_SEC_DR_PIN2 27
// resistance heating 
// Heat/Cool4 on Liu's board
//#define MULTI_PRIM_DR_PIN3 13
//#define MULTI_SEC_DR_PIN3 12
#define FAN_DR_PIN 5

#define LED_PIN	17

#define FAN_SPEED_PIN_0 21
#define FAN_SPEED_PIN_1 19
#define FAN_SPEED_PIN_2 18

// heat/cool by TEC, module cooled by fan
#define MODEL_TEC_CYCLER

#endif

#define HEAT_UP_CONTROL_CHANNEL 0

#ifdef MODEL_RES_HEATER
/**/#define THERMAL_SOURCE_RES
/**/
/**/#define COOL_DOWN_CONTROL_CHANNEL 2 // with fan
/**/#define FAN_CONTROL_CHANNEL 2 // same fan
/**/
/**/#define HEAT_DR_PIN PRIM_DR_PIN
/**/#define FAN_DR_PIN THIRD_DR_PIN

#endif

#ifdef MODEL_TEC_REGULATOR
/**/#define THERMAL_SOURCE_TEC
/**/
/**/#define COOL_DOWN_CONTROL_CHANNEL 1 // with fan
/**/#define FAN_CONTROL_CHANNEL 2 // seperate fan
/**/
/**/#define HEAT_DR_PIN PRIM_DR_PIN
/**/#define COOL_DR_PIN SEC_DR_PIN
#endif

#ifdef MODEL_TEC_CYCLER
/**/#define THERMAL_SOURCE_TEC_HIGH_POWER
/**/
/**/#define COOL_DOWN_CONTROL_CHANNEL 1 // with fan
/**/#define FAN_CONTROL_CHANNEL 2// no fan
#endif

/*
For single-channel, single sample-sensor
*/
#define TEMP_ADC_SDA 32
#define TEMP_ADC_SCL 33

/*
For multi-channel, multi-position sample sensor
*/
#define DRIVER_TEMP_SDA            0
#define DRIVER_TEMP_SCL            2

#define SAMPLE_TEMP_SDA            23
#define SAMPLE_TEMP_SCL            22
/*
End of for multi-channel
*/

#define INTERNAL_TEMP_ADC_PIN 35

#define SERIAL_IN_BUFFER_SIZE 254
#define SERIAL_OT_BUFFER_SIZE 254


// #define DEBUG_LOG

const char version[] = "2024.12.05.a";
// 2023.08.31.b: make heat up curve more aggressive
// 2023.10.07.b: add /q quiet mode, add heart beat mode
// 2023.10.07.c: add temp recording and auto-stop on stable temp
// 2023.10.07.d: error mode if no temp reading available
// 2024.09.02.a: use PID conrol
// 2024.12.05.a: achieve stable temperature rise of the heating module

#define CONTROL_MODE_PID
//#define CONTROL_BANGBANG

/* Temperature */
#define TEMP_VALID_MIN -8
#define TEMP_VALID_MAX 150
// all error code must be below this 
#define ERROR_TEMP_NOT_DEFINED -300
#define ERROR_TEMP_CONVERSION_INVALID -301
#define ERROR_TEMP_READ_TIMEOUT -302

#define LIMIT_MAXSIZE_PID 100
#define LIMIT_MINSIZE_PID 0

#define ALLOW_NEAR_WARNING_TEMP 5

#define IS_TEMP_VALID(x) (x>ERROR_TEMP_NOT_DEFINED)

#define MAX_CONTAINER_PLATE_TEMP_DIFF 20
#define TEMP_SAFETY_MARGIN 5

#define HEAT_WARMING_UP_TIME 10
#define COOL_WARMING_UP_TIME 8
#define EARLT_INTO_CONSTANT_RATE 0.95
#define COOL_CONSTANT_RATE 1.05
#define HEAT_BIAS_TEMP 12
#define COOL_BIAS_TEMP -10

#ifdef THERMAL_SOURCE_TEC_HIGH_POWER
/**/#define DEV_MODEL "tec_cycler_with_fan_cooler"
#else
/**/#ifdef THERMAL_SOURCE_TEC
/**//**/#define DEV_MODEL "tec_regulator_with_liquid_cooler"
/**/#else
/**//**/#define DEV_MODEL "res_heater_with_fan_cooler"
#endif
#endif

#endif